This notebook can be used to generate tradeoff values from all the Pareto-optimal data point files hard-coded in the dictionary pfs. Currently this notebook processes these Pareto-optimal fronts.
%matplotlib notebook
%reload_ext autoreload
%autoreload 2
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as mc
from mpl_toolkits.mplot3d import Axes3D
plt.rcParams.update({'figure.max_open_warning': 0})
We generate and plot at the same time. The $\mu$ values will be saved in the same corresponding directories where the objective values are read from. During the plotting, will change the point size w.r.t. $\mu$ values. For coloring, we will use default color for non-constrained problems and use cm.cool for problems with constraint functions. The knee points will be colored as dark red.
sys.path.append('../')
from vis.utils import dm
from vis.utils import transform as tr
pfs = {'dtlz2': ['3d', '4d', '8d'], \
'dtlz2-nbi': ['3d', '4d', '8d'], \
'debmdk': ['3d', '4d', '8d'], \
'debmdk-nbi': ['3d', '4d', '8d'], \
'debmdk-all': ['3d', '4d', '8d'], \
'debmdk-all-nbi': ['3d', '4d', '8d'], \
'dtlz8': ['3d', '4d', '6d', '8d'], \
'dtlz8-nbi': ['3d', '4d', '6d', '8d'], \
'c2dtlz2': ['3d', '4d', '5d', '8d'], \
'c2dtlz2-nbi': ['3d', '4d', '5d', '8d'], \
'cdebmdk': ['3d', '4d', '8d'], \
'cdebmdk-nbi': ['3d', '4d', '8d'], \
'c0dtlz2': ['3d', '4d', '8d'], \
'c0dtlz2-nbi': ['3d', '4d', '8d'], \
'gaa': ['10d'], \
'gaa-nbi': ['10d']}
eps = dm.epsilons
for pf in list(pfs.keys())[:-2]:
fig = plt.figure(figsize = (9, 3), constrained_layout = True)
c = len(pfs[pf])
c_ = 1
for dim in pfs[pf]:
fullpathf = "../data/{0:s}/{1:s}/dataf.csv".format(pf, dim)
if os.path.exists(fullpathf):
path, filenamef = os.path.split(fullpathf)
dirs = path.split('/')
frontname = dirs[-2]
F = np.loadtxt(fullpathf, delimiter = ',')
print(fullpathf, F.shape, dirs, frontname)
Mu,Ik = dm.tradeoff(F, epsilon = eps[dim], penalize_extremes = False)
mupathf = os.path.join(path, "mu.csv")
np.savetxt(mupathf, Mu, delimiter = ',', fmt = "%1.4e")
muidxpathf = os.path.join(path, "muid.csv")
np.savetxt(muidxpathf, Ik, delimiter = ',', fmt = "%d")
# default color array
C = tr.default_color(F.shape[0], alpha = 0.5)
# change the size w.r.t. Mu, the values are
# too big for smaller size plots, so we make
# them half.
S = tr.resize_by_tradeoff(Mu, k = Ik) / 2
# load CV if exists, use it for coloring
cvpathf = os.path.join(path, "datacv.csv")
if os.path.exists(cvpathf):
CV = np.loadtxt(cvpathf, delimiter = ',')
C = tr.color_by_cv(CV)
# enhance the knees with red
C = tr.enhance_color(C, Ik)
# plot
ax = fig.add_subplot(1, c, c_, projection = '3d')
ax.scatter(F[:,0], F[:,1], F[:,2], color = C, s = S)
c_ = c_ + 1
else:
print("Error: {:s} not found.".format(fullpathf))
plt.show()